package io.gitee.dqcer.mcdull.uac.provider.web.appointment.service.impl;

import java.util.ArrayList;
import java.util.List;

import io.gitee.dqcer.mcdull.uac.provider.system.mapper.SysUserMapper;
import io.gitee.dqcer.mcdull.uac.provider.web.appointment.domain.CarAppointment;
import io.gitee.dqcer.mcdull.uac.provider.web.appointment.domain.CarAppointmentVO;
import io.gitee.dqcer.mcdull.uac.provider.web.appointment.mapper.CarAppointmentMapper;
import io.gitee.dqcer.mcdull.uac.provider.web.appointment.service.ICarAppointmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 预约管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-12-10
 */
@Service
public class CarAppointmentServiceImpl implements ICarAppointmentService
{
    @Autowired
    private CarAppointmentMapper carAppointmentMapper;

    @Resource
    private SysUserMapper sysUserMapper;

    /**
     * 查询预约管理
     * 
     * @param appointmentId 预约管理主键
     * @return 预约管理
     */
    @Override
    public CarAppointment selectCarAppointmentByAppointmentId(Long appointmentId)
    {
        return carAppointmentMapper.selectCarAppointmentByAppointmentId(appointmentId);
    }

    /**
     * 查询预约管理列表
     * 
     * @param carAppointment 预约管理
     * @return 预约管理
     */
    @Override
    public List<CarAppointmentVO> selectCarAppointmentList(CarAppointment carAppointment)
    {
        List<CarAppointmentVO> list = new ArrayList<>();
        List<CarAppointment> appointments = carAppointmentMapper.selectCarAppointmentList(carAppointment);
        for (CarAppointment appointment : appointments) {
            CarAppointmentVO vo = this.convertVO(appointment);
            vo.setNickName(sysUserMapper.selectUserById(vo.getUserId()).getNickName());
            list.add(vo);
        }
        return list;
    }

    private CarAppointmentVO convertVO(CarAppointment appointment) {
        CarAppointmentVO carAppointmentVO = new CarAppointmentVO();
        carAppointmentVO.setAppointmentId(appointment.getAppointmentId());
        carAppointmentVO.setUserId(appointment.getUserId());
        carAppointmentVO.setServiceType(appointment.getServiceType());
        carAppointmentVO.setAppointmentTime(appointment.getAppointmentTime());
        carAppointmentVO.setCreatedAt(appointment.getCreatedAt());
        carAppointmentVO.setUpdatedAt(appointment.getUpdatedAt());
        carAppointmentVO.setSearchValue(appointment.getSearchValue());
        carAppointmentVO.setCreateBy(appointment.getCreateBy());
        carAppointmentVO.setCreateTime(appointment.getCreateTime());
        carAppointmentVO.setUpdateBy(appointment.getUpdateBy());
        carAppointmentVO.setUpdateTime(appointment.getUpdateTime());
        carAppointmentVO.setRemark(appointment.getRemark());
        carAppointmentVO.setParams(appointment.getParams());
        return carAppointmentVO;
    }

    /**
     * 新增预约管理
     * 
     * @param carAppointment 预约管理
     * @return 结果
     */
    @Override
    public int insertCarAppointment(CarAppointment carAppointment)
    {
        return carAppointmentMapper.insertCarAppointment(carAppointment);
    }

    /**
     * 修改预约管理
     * 
     * @param carAppointment 预约管理
     * @return 结果
     */
    @Override
    public int updateCarAppointment(CarAppointment carAppointment)
    {
        return carAppointmentMapper.updateCarAppointment(carAppointment);
    }

    /**
     * 批量删除预约管理
     * 
     * @param appointmentIds 需要删除的预约管理主键
     * @return 结果
     */
    @Override
    public int deleteCarAppointmentByAppointmentIds(Long[] appointmentIds)
    {
        return carAppointmentMapper.deleteCarAppointmentByAppointmentIds(appointmentIds);
    }

    /**
     * 删除预约管理信息
     * 
     * @param appointmentId 预约管理主键
     * @return 结果
     */
    @Override
    public int deleteCarAppointmentByAppointmentId(Long appointmentId)
    {
        return carAppointmentMapper.deleteCarAppointmentByAppointmentId(appointmentId);
    }
}
